


clear 
set scheme lean2, permanent
global pm = char(177)
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 
global path_data_processed "\data\processed"
global path_output "\data\output"
global path_profforecasters "\data\SPF" // place SPF data into this folder


cd "$path_profforecasts"
use "SPF.dta", clear

gen pfid=_n

gen recession_digits=substr(recession,-2,2)
gen recession_int=substr(recession,-5,2)
replace recession_int=substr(recession,-4,1) if recession_int==""

destring recession_digits, replace
destring recession_int, replace

gen posterior_profforecast=recession_int+recession_digits/100

keep pfid posterior_profforecast


if "$user" == "/Users/christopherroth"{
save "SPF_clean.dta", replace
}

if "$user" != "/Users/christopherroth"{
saveold "SPF_clean.dta", v(13) replace
}

cd "$path_data"
use "RN_complete.dta", clear

keep if empl_ft==1
drop if posterior==.

cd "$path_profforecasts"
append using "SPF_clean.dta"


gen posterior_highrecession = posterior if treatment==1
gen posterior_lowrecession = posterior if treatment==0

tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 7

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 2

loc statnames ""
loc varlabels ""

/* Custom fill cells */

use `main', clear

foreach yvar of varlist posterior_profforecast prior posterior_highrecession posterior_lowrecession{
qui sum `yvar', d

	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(p50)', "%9.2f"): col3
	cap: estadd loc thisstat`count' = string(`r(p75)'-`r(p25)', "%9.2f"): col4
	cap: estadd loc thisstat`count' = string(`r(min)', "%9.2f"): col5
	cap: estadd loc thisstat`count' = string(`r(max)', "%9.2f"): col6
	cap: estadd loc thisstat`count' = `r(N)': col7

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc count = `count' + 1
}


forval i = 1/`count' {
	loc statnames "`statnames' thisstat`i'"
}
loc rowlabels " " " "Probability: Recession (SPF)" "Prior: Recession (online panel)" "Posterior: High Recession (online panel)" "Posterior: Low Recession (online panel)" " " "\hline" " "   "
	
/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"

loc footnote "This table presents basic summary statistics for each row variable."

cd "$path_draft"
esttab col* using "RN_SPF_recession", booktabs cells(none) nonum nogap mtitle("Mean" "SD" "Median" "IQR" "Min." "Max." "Obs.") stats(`statnames', labels(`rowlabels')) note("`footnote'") prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear





















 
 
